#include "board_hardware_config.h"

//#define FLASH_PROTECT
__asm void SystemReset(void)
{
    MOV R0, #1           //; 
    MSR FAULTMASK, R0    //; ??FAULTMASK ????????
    LDR R0, =0xE000ED0C  //;
    LDR R1, =0x05FA0004  //; 
    STR R1, [R0]         //; ??????   
 
deadloop
    B deadloop        //; ???????????????
}

void NVIC_Configuration(void)
{

	/* Configure the SysTick handler priority */
    #ifdef  IAP_ENABLE  
	   #ifdef _DEBUG
	  /* Set the Vector Table base location at 0x20000000 */ 
	  NVIC_VectTableSet(NVIC_VECTTAB_FLASH, 0x4000); 
	  #else
         NVIC_VectTableSet(NVIC_VECTTAB_FLASH, 0x2800); 
	  #endif
    #else  /* VECT_TAB_FLASH  */
	  /* Set the Vector Table base location at 0x08000000 */ 
	  NVIC_VectTableSet(NVIC_VECTTAB_FLASH, 0x0);   
   #endif
}

void board_init(void)
{
   /* TIM4 clock enable */
    /* SWJ GPIO REMAP*/
	//GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable,ENABLE);

  
	
	/* Enable GPIOA */
	RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOA, ENABLE);
       
    /* Enable GPIOB */
	RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOB, ENABLE);

	/* Enable GPIOC clock */
	RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOC, ENABLE);

	RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_GPIOD, ENABLE);

    /*USART1 clocks*/
    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_USART1, ENABLE);
    
	/*USART3 clocks */
	RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_USART3, ENABLE);

	//RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_AF, ENABLE);
	
	 
	 
    debug_init(115200);
    SysTick_Configuration();
    dev_uart1_init(115200);
  

    #ifdef FLASH_PROTECT


    #endif 
	
    
}


